#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>

int main()
{
	char path[50] = {0};
	DIR	*dir = NULL;
	struct dirent *dent = NULL;
	char file[100] = {0};
	struct stat st;
	int ret = 0;

	memset(&st,0,sizeof(struct stat));

	printf("please input path:\n");
	scanf("%s",path);

	strcpy(file,path);

	dir = opendir(path);
	if(dir == NULL)
	{
		perror("opendir");
		exit(-1);
	}

	dent = readdir(dir);
	while(dent != NULL)
	{
		strcat(file,dent->d_name);
		ret = stat(file,&st);
		if(ret == -1)
		{
			perror("stat");
			closedir(dir);
			exit(-1);
		}
		if(S_ISDIR(st.st_mode))
		{
			printf("directory:");
			printf("%s %ld\n",dent->d_name,st.st_size);
		}else if(S_ISREG(st.st_mode))
		{
			printf("normalfile:");
			printf("%s %ld\n",dent->d_name,st.st_size);

		}
		dent = readdir(dir);

		strcpy(file,path);
	}

	closedir(dir);

	return 0;
}
